package com.kanasco.engg.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import bb.access.po.Part;
import bb.common.PartPK;

import com.kanasco.engg.model.Item;
import com.kanasco.engg.services.IItemService;

public class UpdateItemController extends SimpleFormController {
	IItemService itemService;
	@SuppressWarnings("deprecation")
	public UpdateItemController(){
		setCommandClass(Item.class);
		setCommandName("item");
	}
	
	public ModelAndView onSubmit(Object command,BindException errors)throws Exception{
		System.out.println("this is updateController");
		Item item=(Item)command;
		//Item item=new Item();
		Part part=new Part();
		PartPK pk=new PartPK();
		
		//pk.setPartNumber(item.getPartNumber());
		pk.setPartType(item.getPartType());
		pk.setPartNumber(item.getPartNumber());
		System.out.println("Part num"+item.getPartNumber());
		
	
	    part.setPk(pk);
		part.setCountryOrigin(item.getCountryOrigin());
		part.setPartUnit(item.getPartUnit());
		part.setMakeBuy(item.getMakeBuy());
		part.setComment(item.getComment());
		part.setLastUser("Prasad");
		itemService.updateItems(part);
		
		//String url=getSuccessView();
		return new ModelAndView("updateSuccess","item",item);
	}
	public void setItemService(IItemService itemService) {
		this.itemService = itemService;
	}
	
}
